package util;

import java.util.regex.Matcher;

/*
 * 字符串判断
 * */

import java.util.regex.Pattern;

public class StringUtil {
	/**
	 * 判断字符串是否为空
	 * @param str
	 * @return
	 */
	public static boolean isEmpty(String str){
		if("".equals(str)||str==null){
			return true;
		}else{
			return false;
		}
	}
	/**
	 * 判断字符串是否不为空
	 * @param str
	 * @return
	 */
	public static boolean isNotEmpty(String str){
		if(!"".equals(str)&&str!=null){
			return true;
		}else{
			return false;
		}
	}
    /**  
     * 判断是否是邮箱 
     * @param email  
     * @return  
     */  
    public static boolean checkEmail(String email){  
     boolean flag = false;  
     try{  
      String check = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";  
      Pattern regex = Pattern.compile(check);  
      Matcher matcher = regex.matcher(email);  
      flag = matcher.matches();  
     }catch(Exception e){  
      flag = false;  
     }  
       
     return flag;  
    }  
    /**  
     * 判断是否是手机号 
     * @param mobiles  
     * @return  [0-9]{5,9}  
     */  
    public static boolean isMobileNO(String mobiles){  
     boolean flag = false;  
     try{  
      Pattern p = Pattern.compile("^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$");
//      ^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$  
      Matcher m = p.matcher(mobiles);  
      flag = m.matches();  
     }catch(Exception e){  
      flag = false;  
     }  
     return flag;  
    }  
      
  /**
   * 判断是否是数字
   * @param str
   * @return
   */
    public static boolean isNum(String str){	
    	return str.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$");	
    	}

    public static void main(String[] args) {
		System.out.println(isNum("123a"));
		//false
		
	}

}  
